import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @author zfChen
 * @create 2022/7/6 9:53
 */
@Slf4j
public class JdkFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 1、线程池
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        // 2、提交任务
        Future<Integer> future = executorService.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.info("执行计算");
                Thread.sleep(1000);
                return 50;
            }
        });

        // 3、主线程通过future获取结果
        log.info("等待结果");
        log.info("结果是：{}",future.get());
        log.info("end");
        executorService.shutdown();
    }

    public void apple(){}
}
